package com.dwxt.community.admin.controller;

import com.dwxt.common.base.BaseResult;
import com.dwxt.common.base.StatusCode;
import com.dwxt.community.admin.service.OperationManagerService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Pattern;

@RestController
@RequestMapping("/cms/admin/operationManager")
public class OperationManagerControllerAdmin {

    @Autowired
    private OperationManagerService operationManagerService;

    @RequestMapping("/targerData")
    public BaseResult operationTargerData(String year, String month){
        String date = null;
        if (ObjectUtils.isNotEmpty(year)){
            date = year;
            if (ObjectUtils.isNotEmpty(month)){
                date = year+month;
            }
        }
        return BaseResult.ok(operationManagerService.operationTargerData(date));
    }
    @RequestMapping("/targerMonthData")
    public BaseResult operationTargerData(){
        String date = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        String format = sdf.format(new Date());
        List<String> list=new ArrayList<String>(Arrays.asList(new String[]{"01","02","03","04","05","06","07","08","09","10","11","12"}));
        TreeMap<Object, Object> map = new TreeMap<>();
        for (int i = 0; i < 12; i++) {
            date = format+"-"+list.get(i);
            LinkedHashMap linkedHashMap = operationManagerService.operationTargerData(date);
            map.put(date,linkedHashMap);
        }
        return BaseResult.ok(map);
    }
}
